<?php

namespace app\api\controller;

use think\Cache;

class Time
{


    public static function isRun($key, $second = 60, $return = false)
    {
        if (Cache::has($key)) {
            if ($return) {
                return false;
            } else {
                exit;
            }
        } else {
            Cache::set($key, 1, $second);
        }
        if ($return) {
            return true;
        }
    }

    public static function removeRun($key, $num = 3)
    {
        if ($num > 0) {
            try {
                Cache::rm($key);
            } catch (\Exception $e) {
                self::removeRun($key, --$num);
            }
        }
    }

}